package com.jessechanrui.template.skeleton.common.base;

/**
 *
 * @author chenrui
 * @date 2024/1/29
 */

import com.jessechanrui.template.skeleton.common.constant.BusinessStatusCode;
import com.jessechanrui.template.skeleton.common.constant.IStatusCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 响应结果基类
 *      接口返回结果，不带对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@ApiModel(value = "基础返回信息", description = "基础返回信息")
public class BaseResponse implements Serializable {

    private static final long serialVersionUID = -7671756385477179547L;

    /**
     * 返回码
     */
    @ApiModelProperty("返回编码")
    protected Integer code = BusinessStatusCode.SUCCESS.getCode();
    /**
     * 返回消息
     */
    @ApiModelProperty("返回信息")
    protected String message = BusinessStatusCode.SUCCESS.getMessage();

    /**
     * 服务器时间
     */
    @ApiModelProperty("系统时间")
    protected long serverTime = System.currentTimeMillis();

    public BaseResponse(IStatusCode iStatusCode) {
        this.code = iStatusCode.getCode();
        this.message = iStatusCode.getMessage();
    }

    public BaseResponse(String message) {
        this.message = message;
    }

    /**
     * 是否成功
     */
    @ApiModelProperty("是否成功")
    public boolean isSuccess() {
        return BusinessStatusCode.SUCCESS.getCode().equals(code);
    }
}
